home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue29 / s3demo / S3DEMO.ZIP / Scripts.ZIP / IniFiles.txt < prev    next >
Encoding:
Text File  |  1997-11-28  |  4.7 KB  |  136 lines

  1. /*
  2.  * Define language 'furniture' as low-order token
  3.  * values, this way 'keywords' can be added later
  4.  * starting at a higher value.
  5.  */
  6. #define it_DEFAULT                   0
  7. #define it_SECTIONSTART              1
  8. #define it_SECTIONNAME               2
  9. #define it_KEYNAME                   3
  10. #define it_VALUE                     4
  11. #define it_EQUAL                     5
  12. #define it_COMMENT                   6
  13.  
  14. /*
  15.  * Standard stuff
  16.  */
  17. #define _non_alpha_                  '[^_A-Za-z0-9]'
  18. #define _all_chars_                  '[\x00-\xFF]'
  19. #define _no_chars_                   '[]'
  20. #define _dont_care_                  _all_chars_
  21. #define _DEFAULT_BACKGROUND          clWhite
  22. #define _DEFAULT_FOREGROUND          clBlack
  23. /*
  24.  * States used as below:
  25.  *
  26.  *  ss_START        Default entry state
  27.  *  ss_INSECTION    Between '[' and ']'
  28.  */
  29. #define ss_START                     0
  30. #define ss_InSECTION                 1
  31. #define ss_EQUAL                     2
  32.  
  33. %%language
  34. Name                                 = 'INIfiles'
  35. Case                                 = __INSENSITIVE
  36. Options                              = __DEFAULT_OPTIONS
  37. WordWrapColumn                       = _EDGE
  38. Gutter                               = _DEFAULT_GUTTER
  39. ExampleText                          = '[Section]\n\
  40.                                        \KeyName=Value\n'
  41. EditableStyles                         ('Section',      it_SECTIONSTART),
  42.                                        ('Section name', it_SECTIONNAME),
  43.                                        ('KeyName',      it_KEYNAME),
  44.                                        ('Value',        it_VALUE),
  45.                                        ('Equal',        it_EQUAL)
  46.  
  47. %%words
  48. //
  49. // Section names start with '[' at beginning of line
  50. //
  51. '\['       _dont_care_                 it_SECTIONSTART        [ss_START]
  52. '\n\['     _dont_care_                 it_SECTIONSTART        [ss_START]
  53. //
  54. // Properties are indicated by '=' within the line
  55. //
  56. '='        _dont_care_                 it_VALUE               [ss_START]
  57. '='        _dont_care_                 it_EQUAL               [ss_EQUAL]
  58. '\n'       _dont_care_                 it_KEYNAME             [ss_START]
  59. '\n;'      _dont_care_                 it_COMMENT             [ss_START]
  60.  
  61. /*
  62.  * Handlers...
  63.  *
  64.  *   '['......Everything up to next ']' or end of line
  65.  *   '='......Everything up to end of line
  66.  */
  67. %%handler
  68. it_SECTIONSTART    _all_chars_?                '[\]\n]'       _use_
  69. it_VALUE           '[^\n\xFF]'?                '[\n\xFF]'     _discard_
  70. it_COMMENT         _all_chars_?                '\n'           _discard_
  71. it_KEYNAME         Match(1)
  72.  
  73. /*
  74.  * Tokens...
  75.  *
  76.  * Keyname...
  77.  */
  78. %%tokens
  79. it_SECTIONNAME     '[^\[\n]'      '[^\]\n]'    '[\]\n]'      _discard_     [ss_INSECTION]
  80.  
  81. %%effects
  82. it_DEFAULT         []                          _DEFAULT_FOREGROUND _DEFAULT_BACKGROUND
  83. it_SECTIONSTART    [fsBold]                    clBlue              _DEFAULT_BACKGROUND
  84. it_EQUAL           [fsBold]                    clAqua              _DEFAULT_BACKGROUND
  85. it_KEYNAME         [fsBold]                    clMaroon            _DEFAULT_BACKGROUND
  86. it_VALUE           []                          _DEFAULT_FOREGROUND _DEFAULT_BACKGROUND
  87. it_COMMENT         [fsItalic]                  clBlue              _DEFAULT_BACKGROUND
  88. it_SECTIONNAME     [fsBold, fsUnderline]       clRed               _DEFAULT_BACKGROUND
  89.  
  90. %%map
  91. it_DEFAULT         it_DEFAULT
  92. it_SECTIONSTART    it_SECTIONSTART
  93. it_KEYNAME         it_KEYNAME
  94. it_VALUE           it_VALUE
  95. it_EQUAL           it_EQUAL
  96. it_SECTIONNAME     it_SECTIONNAME
  97. it_COMMENT         it_COMMENT
  98.  
  99. %%containers
  100. it_SECTIONSTART    (+[ss_INSECTION] -[ss_START])
  101. it_VALUE           (+[ss_EQUAL]     -[ss_START])
  102.  
  103. /*
  104.    The above script uses Match(1) to identify non-key/value pair lines.
  105.    This requires code attached to the OnCustomParse event handler.
  106.    Paste the following code into the event handler:
  107.  
  108.   //
  109.   // INI parser support functions...
  110.   //
  111.   result := true;
  112.   case ParseID of
  113.     1  :   //
  114.            // Newline (without recognised follower)
  115.            //
  116.            // Scan until one of the following is located:
  117.            //    \n      ------    Return entire line as default
  118.            //    =       ------    Return as key name
  119.            //
  120.            with IStream do begin
  121.              while (not yyeof) and (not (yychar in [#13, '='])) do begin
  122.                yyadvance;
  123.                inc(kLength);
  124.               end;
  125.              if yyeof
  126.               then kValue := 0 else
  127.              case yychar of
  128.                #13       : kValue := 0; // Default token value
  129.                '='       : kValue := 3; // Key token value
  130.              end;
  131.            end;
  132.   end;
  133.  
  134. */
  135.    
  136.